<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/6/18
 * Time: 22:59
 */
namespace App\Lib\Sdk\Spider;

use App\Lib\Request\Client;
use App\Lib\Sdk\Spider\Service\Spider;
use App\Models\System;
use App\Models\User;

/**
 * Class PddSpider
 * @package App\Lib\Sdk\Spider
 * https://open.pinduoduo.com/application/document/api?id=pdd.ddk.goods.search
 */
class PddSpider extends BaseSpider implements Spider
{


    protected $defaultParams = [
        'type' => '',
        'client_id' => '',
      //  'access_token' => '',
        'timestamp' => '',
        'data_type' => 'JSON'
    ];


    public function __construct($config, Client $client)
    {
        parent::__construct($config, $client);
        $this->defaultParams['client_id'] = $config['client_id'];
    }

    protected function generateSign($params)
    {
        $params['timestamp'] = time();
        $params = array_filter($params, function($item) {
            if ($item === null || $item === "") {
                return false;
            }
            return true;
        });
        ksort($params);
        $str = "";
        foreach ($params as $k => $v) {
            $str .= $k.$v;
        }
        $str = $this->config['client_secret'] . $str . $this->config['client_secret'];
        $sign = strtoupper(hash("md5", $str));
        $params['sign'] = $sign;
        return $params;
    }


    /**
     * @param array $pddConfig
     * @return array|bool
     *
     * goods_search_response	OBJECT		response
    goods_list	OBJECT[]		商品列表
    activity_tags	INTEGER[]		商品活动标记数组，例：[4,7]，4-秒杀 7-百亿补贴等
    activity_type	INTEGER		活动类型，0-无活动;1-秒杀;3-限量折扣;12-限时折扣;13-大促活动;14-名品折扣;15-品牌清仓;16-食品超市;17-一元幸运团;18-爱逛街;19-时尚穿搭;20-男人帮;21-9块9;22-竞价活动;23-榜单活动;24-幸运半价购;25-定金预售;26-幸运人气购;27-特色主题活动;28-断码清仓;29-一元话费;30-电器城;31-每日好店;32-品牌卡;101-大促搜索池;102-大促品类分会场;
    category_id	LONG		商品类目ID，使用pdd.goods.cats.get接口获取
    category_name	STRING		商品类目名
    cat_ids	LONG[]		商品类目id
    clt_cpn_batch_sn	STRING		店铺收藏券id
    clt_cpn_discount	LONG		店铺收藏券面额,单位为分
    clt_cpn_end_time	LONG		店铺收藏券截止时间
    clt_cpn_min_amt	LONG		店铺收藏券使用门槛价格,单位为分
    clt_cpn_quantity	LONG		店铺收藏券总量
    clt_cpn_remain_quantity	LONG		店铺收藏券剩余量
    clt_cpn_start_time	LONG		店铺收藏券起始时间
    coupon_discount	LONG		优惠券面额，单位为分
    coupon_end_time	LONG		优惠券失效时间，UNIX时间戳
    coupon_min_order_amount	LONG		优惠券门槛价格，单位为分
    coupon_remain_quantity	LONG		优惠券剩余数量
    coupon_start_time	LONG		优惠券生效时间，UNIX时间戳
    coupon_total_quantity	LONG		优惠券总数量
    create_at	LONG		创建时间（unix时间戳）
    desc_txt	STRING		描述分
    goods_desc	STRING		商品描述
    goods_gallery_urls	STRING[]		商品轮播图
    goods_id	LONG		商品id
    goods_image_url	STRING		商品主图
    goods_name	STRING		商品名称
    goods_thumbnail_url	STRING		商品缩略图
    has_coupon	BOOLEAN		商品是否有优惠券 true-有，false-没有
    has_mall_coupon	BOOLEAN		是否有店铺券
    lgst_txt	STRING		物流分
    mall_coupon_discount_pct	INTEGER		店铺券折扣
    mall_coupon_end_time	LONG		店铺券结束使用时间
    mall_coupon_id	LONG		店铺券id
    mall_coupon_max_discount_amount	INTEGER		最大使用金额
    mall_coupon_min_order_amount	INTEGER		最小使用金额
    mall_coupon_remain_quantity	LONG		店铺券余量
    mall_coupon_start_time	LONG		店铺券开始使用时间
    mall_coupon_total_quantity	LONG		店铺券总量
    mall_cps	INTEGER		该商品所在店铺是否参与全店推广，0：否，1：是
    mall_id	LONG		店铺id
    mall_name	STRING		店铺名字
    merchant_type	INTEGER		店铺类型，1-个人，2-企业，3-旗舰店，4-专卖店，5-专营店，6-普通店
    min_group_price	LONG		最小拼团价（单位为分）
    min_normal_price	LONG		最小单买价格（单位为分）
    only_scene_auth	BOOLEAN		快手专享
    opt_id	LONG		商品标签ID，使用pdd.goods.opts.get接口获取
    opt_ids	LONG[]		商品标签id
    opt_name	STRING		商品标签名
    plan_type	INTEGER		推广计划类型 3:定向 4:招商
    promotion_rate	LONG		佣金比例，千分比
    sales_tip	STRING		已售卖件数
    search_id	STRING		搜索id，建议生成推广链接时候填写，提高收益
    service_tags	LONG[]		服务标签: 4-送货入户并安装,5-送货入户,6-电子发票,9-坏果包赔,11-闪电退款,12-24小时发货,13-48小时发货,17-顺丰包邮,18-只换不修,19-全国联保,20-分期付款,24-极速退款,25-品质保障,26-缺重包退,27-当日发货,28-可定制化,29-预约配送,1000001-正品发票,1000002-送货入户并安装
    serv_txt	STRING		服务分
    zs_duo_id	LONG		招商团长id
    list_id	STRING		翻页时必填前页返回的list_id值
    search_id	STRING		搜索id，建议生成推广链接时候填写，提高收益
    total_count	INTEGER		返回商品总数
     */
    public function search(array $pddConfig)
    {
        /*$config = User::getConfig();
        if (empty($config['pdd_pid'])) {
           $pid = $this->createPid($config['uid']);
            User::query()->where("id", $config['uid'])->update(['pdd_pid' => $pid]);
        }*/
        $api = PddApi::search;
        $params = array_merge($this->defaultParams, [
            'type' => $api,
            'pageSize' => 10
        ], $pddConfig);
        $params = $this->generateSign($params);
        $res = $this->client->post("", $params);
        if (isset($res->error_response)) {
            $this->err = $res->error_response->error_msg;
            return false;
        }
        $data = $res->goods_search_response->goods_list->toArray();
        foreach ($data as &$item) {
            $item['shortURL'] = "";
           // $item['shortURL'] = $this->generateLink($item);
        }
        return $data;
    }


    /**
     * @param $data
     * @param string $type  short_url, mobile_short_url
     *
     */
    public function generateLink($data, $uid, $ext = [])
    {

        $api = PddApi::generateLink;
        //$config = User::getConfig($uid);
        $config = System::getConfig();
        $params = array_merge($this->defaultParams, [
            'type' => $api,
            'page_size' => 10
        ], [
            'generate_short_url' => "true",
            'goods_id_list' => json_encode([$data['goods_id']]),
            'p_id' =>  $config->pdd_pid,
            'search_id' => isset($ext['search_id']) ? $ext['search_id'] : "",
            'generate_weapp_webview' => 'true',
            'custom_parameters' => $ext['uid']
        ]);
        $params = $this->generateSign($params);
        $res = $this->client->post("", $params);
        if (isset($res->error_response)) {
            throw new \Exception($res->error_response);
        }
        $lists =  $res->goods_promotion_url_generate_response->goods_promotion_url_list->toArray();
        $model = current($lists);
        //return $model["short_url"];
        return $model['we_app_web_view_short_url'];
    }


    public function getPids()
    {
        $api = "pdd.ddk.goods.pid.query";
        $params = [
            'type' => $api,
        ];
        $params['client_id'] = $this->defaultParams['client_id'];
        $params = $this->generateSign($params);
        $res = $this->client->post("", $params);
        return $res->toArray();
    }
    /**
     * {
    "p_id_generate_response": {
    "p_id_list": [
    {
    "create_time": 0,
    "p_id": "str",
    "pid_name": "str"
    }
    ],
    "remain_pid_count": 0
    }
    }
     *
     *
     * todo 检测
     *
     *
     *
     * object(App\Lib\Request\ResultObject)#1320 (3) { ["__index":protected]=> int(0) ["__data":protected]=> array(1) { ["p_id_generate_response"]=> object(App\Lib\Request\ResultObject)#1322 (5) { ["__index":protected]=> int(0) ["__data":protected]=> array(3) { ["p_id_list"]=> object(App\Lib\Request\ResultObject)#1323 (3) { ["__index":protected]=> int(0) ["__data":protected]=> array(1) { [0]=> object(App\Lib\Request\ResultObject)#1324 (5) { ["__index":protected]=> int(0) ["__data":protected]=> array(3) { ["create_time"]=> int(1592976092) ["pid_name"]=> string(4) "test" ["p_id"]=> string(17) "9755386_145170894" } ["create_time"]=> int(1592976092) ["pid_name"]=> string(4) "test" ["p_id"]=> string(17) "9755386_145170894" } } ["0"]=> object(App\Lib\Request\ResultObject)#1324 (5) { ["__index":protected]=> int(0) ["__data":protected]=> array(3) { ["create_time"]=> int(1592976092) ["pid_name"]=> string(4) "test" ["p_id"]=> string(17) "9755386_145170894" } ["create_time"]=> int(1592976092) ["pid_name"]=> string(4) "test" ["p_id"]=> string(17) "9755386_145170894" } } ["remain_pid_count"]=> int(499995) ["request_id"]=> string(17) "15929760927080583" } ["p_id_list"]=> object(App\Lib\Request\ResultObject)#1323 (3) { ["__index":protected]=> int(0) ["__data":protected]=> array(1) { [0]=> object(App\Lib\Request\ResultObject)#1324 (5) { ["__index":protected]=> int(0) ["__data":protected]=> array(3) { ["create_time"]=> int(1592976092) ["pid_name"]=> string(4) "test" ["p_id"]=> string(17) "9755386_145170894" } ["create_time"]=> int(1592976092) ["pid_name"]=> string(4) "test" ["p_id"]=> string(17) "9755386_145170894" } } ["0"]=> object(App\Lib\Request\ResultObject)#1324 (5) { ["__index":protected]=> int(0) ["__data":protected]=> array(3) { ["create_time"]=> int(1592976092) ["pid_name"]=> string(4) "test" ["p_id"]=> string(17) "9755386_145170894" } ["create_time"]=> int(1592976092) ["pid_name"]=> string(4) "test" ["p_id"]=> string(17) "9755386_145170894" } } ["remain_pid_count"]=> int(499995) ["request_id"]=> string(17) "15929760927080583" } } ["p_id_generate_response"]=> object(App\Lib\Request\ResultObject)#1322 (5) { ["__index":protected]=> int(0) ["__data":protected]=> array(3) { ["p_id_list"]=> object(App\Lib\Request\ResultObject)#1323 (3) { ["__index":protected]=> int(0) ["__data":protected]=> array(1) { [0]=> object(App\Lib\Request\ResultObject)#1324 (5) { ["__index":protected]=> int(0) ["__data":protected]=> array(3) { ["create_time"]=> int(1592976092) ["pid_name"]=> string(4) "test" ["p_id"]=> string(17) "9755386_145170894" } ["create_time"]=> int(1592976092) ["pid_name"]=> string(4) "test" ["p_id"]=> string(17) "9755386_145170894" } } ["0"]=> object(App\Lib\Request\ResultObject)#1324 (5) { ["__index":protected]=> int(0) ["__data":protected]=> array(3) { ["create_time"]=> int(1592976092) ["pid_name"]=> string(4) "test" ["p_id"]=> string(17) "9755386_145170894" } ["create_time"]=> int(1592976092) ["pid_name"]=> string(4) "test" ["p_id"]=> string(17) "9755386_145170894" } } ["remain_pid_count"]=> int(499995) ["request_id"]=> string(17) "15929760927080583" } ["p_id_list"]=> object(App\Lib\Request\ResultObject)#1323 (3) { ["__index":protected]=> int(0) ["__data":protected]=> array(1) { [0]=> object(App\Lib\Request\ResultObject)#1324 (5) { ["__index":protected]=> int(0) ["__data":protected]=> array(3) { ["create_time"]=> int(1592976092) ["pid_name"]=> string(4) "test" ["p_id"]=> string(17) "9755386_145170894" } ["create_time"]=> int(1592976092) ["pid_name"]=> string(4) "test" ["p_id"]=> string(17) "9755386_145170894" } } ["0"]=> object(App\Lib\Request\ResultObject)#1324 (5) { ["__index":protected]=> int(0) ["__data":protected]=> array(3) { ["create_time"]=> int(1592976092) ["pid_name"]=> string(4) "test" ["p_id"]=> string(17) "9755386_145170894" } ["create_time"]=> int(1592976092) ["pid_name"]=> string(4) "test" ["p_id"]=> string(17) "9755386_145170894" } } ["remain_pid_count"]=> int(499995) ["request_id"]=> string(17) "15929760927080583" } }
     *
     * $pid = 9755386_145170894;
     */
    public function createPid($uid)
    {
        return false;

      /*  $params = $this->generateSign([
            'type' =>  PddApi::generatePid,
            'number' => 1,
            'p_id_name_list' => \GuzzleHttp\json_encode([$uid . "的推荐位" . rand(110, 9999000)]),
            'client_id' => $this->config['client_id']
        ]);
        $res = $this->client->post("", $params);
        $res = current($res->toArray());
        $data = $res['p_id_list'];
        $pid = current($data)['p_id'];
        return $pid;*/
    }
    /**
     * @param array $goods
     * thumb_url	STRING		商品缩略图
    goods_id	LONG		商品编码
    goods_name	STRING		商品名称
    image_url	STRING		商品图片
    is_more_sku	INTEGER		是否多sku，0-单sku，1-多sku
    goods_quantity	LONG		商品总数量
    is_onsale	INTEGER		是否在架上，0-下架中，1-架上
    sku_list	OBJECT[]		sku列表对象
    spec	STRING		规格名称
    sku_id	LONG		sku编码
    sku_quantity	LONG		sku库存
    outer_id	STRING		商家外部编码（sku），同其他接口中的outer_id 、out_id、out_sku_sn、outer_sku_sn、out_sku_id、outer_sku_id 都为商家编码（sku维度）。
    outer_goods_id	STRING		商家外部编码（商品），同其他接口中的outer_goods_id 、out_goods_id、out_goods_sn、outer_goods_sn 都为商家编码（goods维度）。
    is_sku_onsale	INTEGER		sku是否在架上，0-下架中，1-架上
    reserve_quantity	LONG		sku预扣库存
     *
     *
     *
     *
     * @return
     * {
    goods_id	LONG		商品id
    rate	INTEGER		佣金比例（千分比）
    rate_to_be	INTEGER		即将生效的全店推广计划佣金比（千分比），若没有则为null
    status	INTEGER		商品状态，1-推广中，2-暂停，3-删除
    status_to_be	INTEGER		即将生效的全店推广计划状态：1-推广中，2-暂停推广，若没有则为null
    coupon_vo	OBJECT		计划使用的优惠券信息。商品没有优惠券将返回null，有优惠券将返回优惠券信息，包括优惠券起始结束时间，优惠券数量，剩余数量，金额等
        coupon_start_time	STRING		coupon_start_time
        coupon_end_time	STRING		coupon_end_time
        discount	INTEGER		discount
        init_quantity	LONG		init_quantity
        remain_quantity	LONG		remain_quantity
        rate_to_be_day	STRING		通用推广计划佣金生效时间
    status_to_be_day	STRING		通用推广计划状态生效时间
    }
     */
    public function getCouponInfo(array $goods)
    {
        $goodsId = $goods['goods_id'];
        $api = PddApi::conpou;
        $params = array_merge($this->defaultParams, [
            'type' => $api,
            'goods_id' => $goodsId
        ]);
        $params = $this->generateSign($params);
        $res = $this->client->post("", $params);
        if (isset($res->error_response)) {
            $this->err = $res->error_response->error_msg;
            return false;
        }
        if ($res->status != 1) {
            $this->err = "商品不在推广状态";
            return false;
        }
        $info = $res->coupon_vo->toArray();
        $info['rate'] = $res->rate;
        return $info;
    }

    /**
     * [{
    "level": 1,
    "cat_name": "男装",
    "cat_id": 239,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "家居建材",
    "cat_id": 2479,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "办公用品",
    "cat_id": 2603,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "文化用品",
    "cat_id": 2629,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "3C数码配件",
    "cat_id": 2933,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "古董\/邮币\/字画\/收藏",
    "cat_id": 5217,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "影音电器",
    "cat_id": 5752,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "手机",
    "cat_id": 5834,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "二手数码",
    "cat_id": 5839,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "电脑",
    "cat_id": 5851,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "数码相机\/单反相机\/摄像机",
    "cat_id": 5906,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "智能设备",
    "cat_id": 5921,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "厨房电器",
    "cat_id": 5955,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "大家电",
    "cat_id": 6076,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "生活电器",
    "cat_id": 6128,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "个人护理保健",
    "cat_id": 6209,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "网络设备",
    "cat_id": 6290,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "零食\/坚果\/特产",
    "cat_id": 6398,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "咖啡\/麦片\/冲饮",
    "cat_id": 6536,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "茶",
    "cat_id": 6586,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "粮油米面\/南北干货\/调味品",
    "cat_id": 6630,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "酒类",
    "cat_id": 6758,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "保健食品\/膳食营养补充食品",
    "cat_id": 6785,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "传统滋补品",
    "cat_id": 6883,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "电子元器件市场",
    "cat_id": 7323,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "摩托车\/装备\/配件",
    "cat_id": 7629,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "汽车\/用品\/配件\/改装",
    "cat_id": 7639,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "水产肉类\/新鲜蔬果\/熟食",
    "cat_id": 8172,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "女装\/女士精品",
    "cat_id": 8439,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "新车\/二手车",
    "cat_id": 8502,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "流行男鞋",
    "cat_id": 8508,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "女鞋",
    "cat_id": 8509,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "箱包皮具\/女包\/男包",
    "cat_id": 8538,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "内衣裤袜",
    "cat_id": 8583,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "腕表眼镜",
    "cat_id": 8634,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "服饰配件",
    "cat_id": 8669,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "本地化生活服务",
    "cat_id": 8721,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "电影\/演出\/体育赛事",
    "cat_id": 8722,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "个性定制\/设计服务",
    "cat_id": 8723,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "购物卡\/礼品卡\/代金券",
    "cat_id": 8724,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "婚庆\/摄影\/摄像服务",
    "cat_id": 8725,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "教育培训",
    "cat_id": 8726,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "景点门票\/周边游",
    "cat_id": 8727,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "旅游路线\/商品\/服务",
    "cat_id": 8728,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "生活缴费",
    "cat_id": 8729,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "影视\/会员\/腾讯QQ专区",
    "cat_id": 8730,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "特价酒店\/客栈\/公寓旅馆",
    "cat_id": 8731,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "网络服务\/软件",
    "cat_id": 8732,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "网上营业厅",
    "cat_id": 8733,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "休闲娱乐",
    "cat_id": 8734,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "游戏服务\/直播",
    "cat_id": 8736,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "床上用品",
    "cat_id": 9313,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "电子\/电工",
    "cat_id": 9314,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "基础建材",
    "cat_id": 9315,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "家居饰品",
    "cat_id": 9316,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "家装灯饰光源",
    "cat_id": 9317,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "家装主材",
    "cat_id": 9318,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "居家布艺",
    "cat_id": 9319,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "全屋定制",
    "cat_id": 9320,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "商业\/办公家具",
    "cat_id": 9321,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "特色手工艺",
    "cat_id": 9322,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "五金工具",
    "cat_id": 9323,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "住宅家具",
    "cat_id": 9324,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "电动车\/配件\/交通工具",
    "cat_id": 11683,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "户外\/登山\/旅行野营用品",
    "cat_id": 11684,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "运动\/瑜伽\/健身\/球类",
    "cat_id": 11685,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "运动包\/户外包\/配件",
    "cat_id": 11686,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "运动服\/休闲服",
    "cat_id": 11687,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "运动鞋",
    "cat_id": 11688,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "自行车\/骑行装备\/零配件",
    "cat_id": 11689,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "OTC药品",
    "cat_id": 13176,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "精制中药材",
    "cat_id": 13177,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "隐形眼镜\/护理液",
    "cat_id": 13178,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "奶粉\/辅食\/营养品\/零食",
    "cat_id": 14697,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "尿片\/洗护\/喂哺\/推车床",
    "cat_id": 14740,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "童鞋\/婴儿鞋\/亲子鞋",
    "cat_id": 14933,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "童装\/婴儿装\/亲子装",
    "cat_id": 14966,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "玩具\/童车\/益智\/积木\/模型",
    "cat_id": 15083,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "孕产妇用品\/孕妇装\/营养",
    "cat_id": 15356,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "书籍\/杂志\/报纸",
    "cat_id": 15543,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "农机\/农具\/农膜",
    "cat_id": 16155,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "畜牧\/养殖物资",
    "cat_id": 16192,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "农用物资",
    "cat_id": 16209,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "成人用品",
    "cat_id": 16237,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "宠物\/宠物食品及用品",
    "cat_id": 16288,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "餐饮具",
    "cat_id": 16548,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "厨房\/烹饪用具",
    "cat_id": 16676,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "收纳整理",
    "cat_id": 16794,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "家庭\/个人清洁工具",
    "cat_id": 16901,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "居家日用",
    "cat_id": 16989,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "节庆用品\/礼品",
    "cat_id": 17134,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "烟品\/打火机\/瑞士军刀",
    "cat_id": 17249,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "洗护清洁剂\/卫生巾\/纸\/香薰",
    "cat_id": 17285,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "饰品\/流行首饰\/时尚饰品",
    "cat_id": 17412,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "珠宝\/钻石\/翡翠\/黄金",
    "cat_id": 17455,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "鲜花速递\/花卉仿真\/绿植园艺",
    "cat_id": 17671,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "乐器\/吉他\/钢琴\/配件",
    "cat_id": 17803,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "装修设计\/施工\/监理",
    "cat_id": 18088,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "医疗健康服务",
    "cat_id": 18270,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "处方药",
    "cat_id": 18349,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "彩妆\/香水\/美妆工具",
    "cat_id": 18482,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "美容美体仪器",
    "cat_id": 18574,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "美发护发\/假发",
    "cat_id": 18601,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "美容护肤\/美体\/精油",
    "cat_id": 18637,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "器械保健",
    "cat_id": 18814,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "婴童尿裤",
    "cat_id": 19298,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "汽车服务",
    "cat_id": 20078,
    "parent_cat_id": 0
    }, {
    "level": 1,
    "cat_name": "房地产",
    "cat_id": 20340,
    "parent_cat_id": 0
    }]
     *
     * 20100-百货，20200-母婴，20300-食品，20400-女装，20500-电器，20600-鞋包，20700-内衣，20800-美妆，20900-男装，21000-水果，
     * 21100-家纺，21200-文具,21300-运动,21400-虚拟,21500-汽车,21600-家装,21700-家具,21800-医药;
     */
    public function getCate()
    {
        $api = "pdd.goods.cats.get";
        $params = array_merge($this->defaultParams, [
            'type' => $api,
            'parent_cat_id' => 0
        ]);
        $params = $this->generateSign($params);
        $res = $this->client->post("", $params);
        echo $res->goods_cats_get_response->goods_cats_list ;
    }


}